public class EqualsDemo{
 int int1;
public SomeClass obj1;

/** constructor*/
public EqualsDemo(int i, SomeClass o){
int1=i;
obj1=o;
   }

public EqualsDemo(){
this(0, new SomeClass());
  }

/** metoda Equals tipica run-of-the-mill */
public boolean equals (Object o){
if(o == null) //avertizare
return false;
if(o == this) //optimizare
return true;
//fabricat prin turnare
if(!(o instanceof EqualsDemo))
return false;

EqualsDemo other = (EqualsDemo)o; //ok, exprimare pentru aceasta clasa
// comparare camp-cu-camp
if(!int1.equals(other.int1)) //compara direct primitivele
return false;

if(!obj1.equals(other.obj1))//compara obiectele utilizand egalul lor
return false;
return true;
}
 }
